/**
 * 减法(处理小数运算精度问题)
 * 思路: 14.312 - 0.47 === (14.312*1000 - 0.47*1000) / 1000 === (14312 - 4700) / (Math.pow(10, 4))
 * @param {String | Number} minustart 减数
 * @param {String | Number} minuend 被减数
 * @return {Number}
*/
function substract(minustart, minuend) {
  const minustartNum = Number(minustart) || 0
  const minuendNum = Number(minuend) || 0
  const minustartStr = minustartNum.toString()
  const minuendStr = minuendNum.toString()

  const precision = Math.max(...[minustartStr,minuendStr].map(str => str.split('.')[1]?.length || 0))
  const ratio = Math.pow(10, precision)

  return (minustartNum * ratio - minuendNum * ratio) / ratio
}

// // 测试
// substract(14.312,0.47)
// // 13.842
// substract(0.3,0.1)
// // 0.2
